package com.example.controller;

import com.example.common.Result;
import com.example.entity.FriendList;
import com.example.service.FriendListService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import java.util.List;

/**
 * 好友列表前端操作接口
 **/
@RestController
@RequestMapping("/friendList")
public class FriendListController {

    @Resource
    private FriendListService friendListService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody FriendList friendList) {
        friendListService.add(friendList);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        friendListService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        friendListService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody FriendList friendList) {
        friendListService.updateById(friendList);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        FriendList friendList = friendListService.selectById(id);
        return Result.success(friendList);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(FriendList friendList) {
        List<FriendList> list = friendListService.selectAll(friendList);
        return Result.success(list);
    }

    @GetMapping("/showPK")
    public Result selectAll(@Param("userId") Integer userId, @Param("friendId") Integer friendId) {
        friendListService.showPk(userId,friendId);
        return Result.success();
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(FriendList friendList,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<FriendList> page = friendListService.selectPage(friendList, pageNum, pageSize);
        return Result.success(page);
    }

}